package com.example.cmh.controller;

import com.example.cmh.common.Result;
import com.example.cmh.pojo.position;
import com.example.cmh.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/position")
@CrossOrigin
public class PositionController {
    @Autowired
    private PositionService positionService;
    @GetMapping("/list")
    public Result getAllPositions() {
        List<position> list = positionService.getAllPositions();
        return Result.success("获取岗位列表成功", list);
    }
    @GetMapping("/{positionId}")
    public Result getPositionById(@PathVariable(name = "positionId") Integer positionId) {
        position pos = positionService.getPositionById(positionId);
        return Result.success("获取岗位成功", pos);
    }
    @PostMapping("/add")
    public Result addPosition(@RequestBody position pos) {
        positionService.addPosition(pos);
        return Result.success("新增岗位成功");
    }
    @PutMapping("/{positionId}")
    public Result updatePosition(@PathVariable(name = "positionId") Integer positionId, @RequestBody position pos) {
        pos.setPositionId(positionId);
        positionService.updatePosition(pos);
        return Result.success("更新岗位成功");
    }
    @DeleteMapping("/{positionId}")
    public Result deletePosition(@PathVariable(name = "positionId") Integer positionId) {
        positionService.deletePosition(positionId);
        return Result.success("删除岗位成功");
    }
} 